const rob = nums => {
  let n = nums.length
  if (n === 0) return 0
  if (n === 1) return nums[0]
  if (n === 2) return Math.max(nums[0], nums[1])
  if (n === 3) return Math.max(nums[0] + nums[2], nums[1])
  const dp = new Array(n + 1);
  dp[0] = 0;
  dp[1] = nums[0];
  for (let i = 2; i <= n; i++) {
    dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);
  }
  return dp[n];
}

console.log(rob([2, 3, 2]));
